package _SED.server;

import _SED.client.DBConnection;
import _SED.client.Rfc;
import _SED.client.User;
import _SED.client.WO;
import _SED.shared.FieldVerifier;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.FetchOptions;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.datastore.PreparedQuery;
import com.google.appengine.api.datastore.Query;
import com.google.appengine.api.datastore.Query.FilterOperator;
import com.google.appengine.api.datastore.Query.SortDirection;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.ListIterator;
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;

import javax.jdo.PersistenceManager;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet implements
		DBConnection {

	public String greetServer(String name) throws IllegalArgumentException {
		// Verify that the input is valid.
		if (!FieldVerifier.isValidName(name)) {
			// If the input is not valid, throw an IllegalArgumentException back
			// to
			// the client.
			throw new IllegalArgumentException(
					"Name must be at least 4 characters long");
		}

		String serverInfo = getServletContext().getServerInfo();
		String userAgent = getThreadLocalRequest().getHeader("User-Agent");

		// Escape data from the client to avoid cross-site script
		// vulnerabilities.
		name = escapeHtml(name);
		userAgent = escapeHtml(userAgent);

		return "Hello, " + name + "!<br><br>greet Server Info" + serverInfo
				+ ".<br><br>It looks adfsf like you are using:<br>" + userAgent;
	}

	/**
	 * Escape an html string. Escaping data received from the client helps to
	 * prevent cross-site script vulnerabilities.
	 * 
	 * @param html
	 *            the html string to escape
	 * @return the escaped string
	 */
	private String escapeHtml(String html) {
		if (html == null) {
			return null;
		}
		return html.replaceAll("&", "&amp;").replaceAll("<", "&lt;")
				.replaceAll(">", "&gt;");
	}

	private final String CU = "Change User", CO = "Change Initiator",
			CI = "Change Owner", CA = "Change Approver", ADM = "Administrator";

	// --------------------------------------------------------------------
	// User Methods
	// --------------------------------------------------------------------

	@Override
	public String[] userAuth(String usr, String pwd)
			throws IllegalArgumentException {
		/*
		 * String serverInfo = getServletContext().getServerInfo(); String
		 * userAgent = getThreadLocalRequest().getHeader("User-Agent");
		 */
		String[] list = new String[6];

		// Escape data from the client to avoid cross-site script
		// vulnerabilities.
		usr = escapeHtml(usr);
		pwd = escapeHtml(pwd);

		// Check if user exists
		if (this.userExists(usr) == false) {
			list[0] = "E001";
			list[1] = "Unknown User: " + usr
					+ "<br><br>Please inform your Administrator<br>"; // +
																		// userAgent;
			return list;
		}

		// Check if pwd is correct
		if (this.checkPassword(usr, pwd) == false) {
			list[0] = "E002";
			list[1] = "Wrong Password"
					+ ".<br><br>Try again, or inform your Administrator<br>"; // +
																				// userAgent;
			return list;
		}

		// Login
		list[0] = "S000";
		list[1] = "Hello, " + usr
				+ "!<br><br>Your authorization succeeded.<br>";

		DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
		Query q = new Query("User");
		q.addFilter("User", Query.FilterOperator.EQUAL, usr);
		PreparedQuery pq = ds.prepare(q);
		Entity user = pq.asSingleEntity();
		if (usr.compareTo("Admin") == 0) {
			list[2] = (String) user.getProperty("Name");
			list[3] = "Chuck";
			list[4] = "Noris";
			list[5] = "Admin";
		} else {
			list[2] = (String) user.getProperty("User");
			list[3] = (String) user.getProperty("FName");
			list[4] = (String) user.getProperty("LName");
			list[5] = (String) user.getProperty("Role");
		}
		return list;

	}

	public String userCreate(String usr, String lname, String fname,
			String role, String pwd) throws IllegalArgumentException {
		try {
			if (this.userExists(usr) == false) {

				DatastoreService ds = DatastoreServiceFactory
						.getDatastoreService();
				Key userKey = KeyFactory.createKey("User", usr);

				Entity user = new Entity("User", userKey);
				user.setProperty("User", usr);
				user.setProperty("LName", lname);
				user.setProperty("FName", fname);
				user.setProperty("Role", role);
				user.setProperty("Pwd", pwd);
				user.setProperty("Date", this.now());
				ds.put(user);

				return "User Account" + usr + "was created";
			} else {
				return "User " + usr + "unknown"
						+ ".<br><br>Please contact your Administrator<br>";
			}
		}

		finally {
		}
	}

	public String[] getUsers() {
		int i = 0;
		String[] uname = new String[100];
		DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
		Query q = new Query("User");
		q.addSort("User", Query.SortDirection.ASCENDING);
		PreparedQuery pq = ds.prepare(q);

		for (Entity user : pq.asIterable()) {
			uname[i] = (String) user.getProperty("User");
			i++;
		}

		return uname;
	}

	// return Change Initiators
	public String[] getCI() {
		int i = 0;
		String[] uname = new String[20];
		DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
		Query q = new Query("User");
		q.addFilter("Role", Query.FilterOperator.EQUAL, "Change Initiator");
		q.addSort("User", Query.SortDirection.ASCENDING);
		PreparedQuery pq = ds.prepare(q);

		for (Entity user : pq.asIterable()) {
			uname[i] = (String) user.getProperty("User");
			i++;
		}
		return uname;
	}

	// return Change Owners
	public String[] getCO() {
		int i = 0;
		String[] uname = new String[20];
		DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
		Query q = new Query("User");
		q.addFilter("Role", Query.FilterOperator.EQUAL, "Change Owner");
		q.addSort("User", Query.SortDirection.ASCENDING);
		PreparedQuery pq = ds.prepare(q);

		for (Entity user : pq.asIterable()) {
			uname[i] = (String) user.getProperty("User");
			i++;
		}
		return uname;
	}

	// return Change Approvers
	public String[] getCA() {
		int i = 0;
		String[] uname = new String[20];
		DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
		Query q = new Query("User");
		q.addFilter("Role", Query.FilterOperator.EQUAL, "Change Approver");
		q.addSort("User", Query.SortDirection.ASCENDING);
		PreparedQuery pq = ds.prepare(q);

		for (Entity user : pq.asIterable()) {
			uname[i] = (String) user.getProperty("User");
			i++;
		}
		return uname;
	}

	// return Change Deployers
	public String[] getCD() throws IllegalArgumentException {
		int i = 0;
		String[] uname = new String[20];
		DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
		Query q = new Query("User");
		q.addFilter("Role", Query.FilterOperator.EQUAL, "Change Deployer");
		q.addSort("User", Query.SortDirection.ASCENDING);
		PreparedQuery pq = ds.prepare(q);

		for (Entity user : pq.asIterable()) {
			uname[i] = (String) user.getProperty("User");
			i++;
		}
		return uname;
	}

	public String[] getUser(String usr) {

		String[] u = new String[5];
		if (this.userExists(usr) == true) {

			String role;
			DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
			Query q = new Query("User");
			q.addFilter("User", Query.FilterOperator.EQUAL, usr);
			PreparedQuery pq = ds.prepare(q);
			Entity user = pq.asSingleEntity();

			u[0] = (String) user.getProperty("User");
			u[1] = (String) user.getProperty("LName");
			u[2] = (String) user.getProperty("FName");
			u[4] = (String) user.getProperty("Pwd");

			role = (String) user.getProperty("Role");

			if (role.equals("Change User"))
				u[3] = "0";
			if (role.equals("Change Initiator"))
				u[3] = "1";
			if (role.equals("Change Owner"))
				u[3] = "2";
			if (role.equals("Change Deployer"))
				u[3] = "3";
			if (role.equals("Change Approver"))
				u[3] = "4";
			if (role.equals("Administrator"))
				u[3] = "5";

		}
		return u;
	}

	public List<Entity> getRoles() {
		DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
		Query q = new Query("Role");
		q.addSort("Role", Query.SortDirection.ASCENDING);
		List<Entity> roleList = ds.prepare(q).asList(null);
		return roleList;
	}

	public List<Entity> getRFCs() {
		DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
		Query q = new Query("RFC");
		q.addSort("ID", Query.SortDirection.ASCENDING);
		List<Entity> rfcList = ds.prepare(q).asList(null);
		return rfcList;
	}

	public WO getWO(long id) {
		DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
		Query q = new Query("WO");
		q.addFilter("ID", Query.FilterOperator.EQUAL, id);
		PreparedQuery pq = ds.prepare(q);
		Entity wo = pq.asSingleEntity();

		if (wo == null) {
			return null;
		} else {
			return new WO((Long) wo.getProperty("ID"),
					(Date) wo.getProperty("PStart"),
					(Date) wo.getProperty("PEnd"),
					(Date) wo.getProperty("AStart"),
					(Date) wo.getProperty("AEnd"),
					(String) wo.getProperty("PEffort"),
					(String) wo.getProperty("CD"),
					(String) wo.getProperty("CO"),
					(String) wo.getProperty("WoType"),
					(String) wo.getProperty("Desc"),
					(String) wo.getProperty("Serv"),
					(String) wo.getProperty("CItem"),
					(String) wo.getProperty("State"));
		}

	}

	public static String now() {
		final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
		Calendar cal = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
		return sdf.format(cal.getTime());
	}

	private boolean userExists(String usr) {
		DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
		Query q = new Query("User");
		q.addFilter("User", Query.FilterOperator.EQUAL, usr);
		PreparedQuery pq = ds.prepare(q);
		Entity user = pq.asSingleEntity();
		if (user == null)
			return false;
		return (boolean) user.getProperty("User").equals(usr);
	}

	private boolean checkPassword(String usr, String pwd) {

		DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
		Query q = new Query("User");
		q.addFilter("User", Query.FilterOperator.EQUAL, usr);
		q.addFilter("Pwd", Query.FilterOperator.EQUAL, pwd);
		PreparedQuery pq = ds.prepare(q);
		Entity user = pq.asSingleEntity();
		if (user == null)
			return false;
		if ((boolean) user.getProperty("User").equals(usr) == true
				&& (boolean) user.getProperty("Pwd").equals(pwd) == true)
			return true;
		else
			return false;

	}

	@Override
	public String userChange(String usr, String lname, String fname,
			String role, String pwd) throws IllegalArgumentException {

		try {
			if (this.userExists(usr) == true) {

				DatastoreService ds = DatastoreServiceFactory
						.getDatastoreService();
				Query q = new Query("User");
				q.addFilter("User", Query.FilterOperator.EQUAL, usr);
				PreparedQuery pq = ds.prepare(q);
				Entity user = pq.asSingleEntity();

				user.setProperty("LName", lname);
				user.setProperty("FName", fname);
				user.setProperty("Role", role);
				user.setProperty("Pwd", pwd);
				user.setProperty("Date", this.now());
				ds.put(user);

				return usr + " User Account has been changed";
			} else {
				return "User unknown: " + usr;
			}
		}

		finally {
		}
	}

	@Override
	public String userDelete(String usr) throws IllegalArgumentException {

		if (this.userExists(usr) == true) {

			DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
			Query q = new Query("User");
			q.addFilter("User", Query.FilterOperator.EQUAL, usr);
			PreparedQuery pq = ds.prepare(q);
			Entity user = pq.asSingleEntity();
			ds.delete(user.getKey());
			return "User: " + usr + "has been deleted";

		}
		return "User: " + usr + "does not exists";

	}

	// --------------------------------------------------------------------
	// RFC Methods
	// --------------------------------------------------------------------
	public String createRFC(long id, String reason, String desc,
			String detailDesc, Date validFrom, String CI, String CO, String CA,
			String prio, String cost, String benefit, String risk,
			String services, String cItem) throws IllegalArgumentException {
		try {
			if (this.rfcExists(id) == false) {

				DatastoreService ds = DatastoreServiceFactory
						.getDatastoreService();
				Key userKey = KeyFactory.createKey("RFC", id);

				Entity rfc = new Entity("RFC", userKey);
				rfc.setProperty("ID", id);
				rfc.setProperty("Reason", reason);
				rfc.setProperty("Desc", desc);
				rfc.setProperty("DDesc", detailDesc);
				rfc.setProperty("ValidFrom", validFrom);
				// rfc.setProperty("ApprovedOn", date);
				// rfc.setProperty("SolvedOn", date);
				// rfc.setProperty("ClosedOn", date);
				rfc.setProperty("CI", CI);
				rfc.setProperty("CO", CO);
				rfc.setProperty("CA", CA);
				rfc.setProperty("Prio", prio);
				rfc.setProperty("Cost", cost);
				rfc.setProperty("Benefit", benefit);
				rfc.setProperty("Risk", risk);
				rfc.setProperty("Serv", services);
				rfc.setProperty("CItem", cItem);
				rfc.setProperty("State", "CREATED");

				ds.put(rfc);

				return "RFC was created with ID: " + id;
			} else {
				return "RFC already exists: " + id
						+ ".<br><br>Please contact your Administrator<br>";
			}
		}

		finally {
		}
	}

	public String changeRfc(long id, String reason, String desc,
			String detaildesc, Date validFrom, Date approvedOn, Date solvedOn,
			Date closedOn, Date startedOn, String CI, String CO, String CA,
			String CD, String prio, String cost, String benefit, String risk,
			String service, String cItems, String state)
			throws IllegalArgumentException {

		if (this.rfcExists(id) == true) {
			DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
			Query q = new Query("RFC");
			q.addFilter("ID", Query.FilterOperator.EQUAL, id);
			PreparedQuery pq = ds.prepare(q);
			Entity rfc = pq.asSingleEntity();

			rfc.setProperty("ID", id);
			rfc.setProperty("Reason", reason);
			rfc.setProperty("Desc", desc);
			rfc.setProperty("DDesc", detaildesc);
			rfc.setProperty("ValidFrom", validFrom);
			rfc.setProperty("ApprovedOn", approvedOn);
			rfc.setProperty("SolvedOn", solvedOn);
			rfc.setProperty("ClosedOn", closedOn);
			rfc.setProperty("DelegatedOn", closedOn);
			rfc.setProperty("StartedOn", startedOn);
			rfc.setProperty("CI", CI);
			rfc.setProperty("CO", CO);
			rfc.setProperty("CA", CA);
			rfc.setProperty("CD", CD);
			rfc.setProperty("Prio", prio);
			rfc.setProperty("Cost", cost);
			rfc.setProperty("Benefit", benefit);
			rfc.setProperty("Risk", risk);
			rfc.setProperty("Serv", service);
			rfc.setProperty("CItem", cItems);
			rfc.setProperty("State", state);

			ds.put(rfc);

			return "RFC successful changed with ID: " + id;
		} else {
			return "RFC does not exists: " + id
					+ ".<br><br>Please contact your Administrator<br>";
		}
	}

	private boolean rfcExists(long id) {
		DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
		Query q = new Query("RFC");
		q.addFilter("ID", Query.FilterOperator.EQUAL, id);
		PreparedQuery pq = ds.prepare(q);
		Entity rfc = pq.asSingleEntity();
		if (rfc == null)
			return false;
		return ((Long) rfc.getProperty("ID") == id);

	}

	public long getNextRfcNr() {

		DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
		Query q = new Query("RFC");
		q.addSort("ID", SortDirection.DESCENDING);
		PreparedQuery pq = ds.prepare(q);
		List<Entity> rfc = pq.asList(FetchOptions.Builder.withLimit(1));
		if (rfc.isEmpty())
			return 1;
		else {
			Long val = (Long) rfc.get(0).getProperty("ID");
			val++;
			return val;
		}

	}

	@Override
	public List<Rfc> fetchRfc(int start, int length) {
		int i = 0;
		DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
		Query q = new Query("RFC");
		q.addFilter("ID", Query.FilterOperator.GREATER_THAN, 0);
		q.addSort("ID", Query.SortDirection.ASCENDING);
		PreparedQuery pq = ds.prepare(q);
		// List<Entity> selectedRfc =
		// pq.asList(FetchOptions.Builder.withLimit(length));

		List<Rfc> rfcList = new ArrayList<Rfc>();

		for (Entity rfc : pq.asIterable()) {

			// while(selectedRfc.iterator().hasNext()){
			// Entity rfc = selectedRfc.iterator().next();
			rfcList.add(new Rfc((Long) rfc.getProperty("ID"), 
					(String) rfc.getProperty("Reason"), 
					(String) rfc.getProperty("Desc"),
					(String) rfc.getProperty("DDesc"), 
					(Date) rfc.getProperty("ValidFrom"), 
					(Date) rfc.getProperty("ApprovedOn"), 
					(Date) rfc.getProperty("SolvedOn"), 
					(Date) rfc.getProperty("ClosedOn"), 
					(Date) rfc.getProperty("DelegetedOn"), 
					(Date) rfc.getProperty("startedOn"), 
					(String) rfc.getProperty("CI"),
					(String) rfc.getProperty("CO"),
					(String) rfc.getProperty("CA"), 
					(String) rfc.getProperty("CD"),
					(String) rfc.getProperty("Prio"),
					(String) rfc.getProperty("Cost"),
					(String) rfc.getProperty("Benefit"),
					(String) rfc.getProperty("Serv"),
					(String) rfc.getProperty("Risk"),
					(String) rfc.getProperty("CItem"),
					(String) rfc.getProperty("State")));
			
		}
		return rfcList;
	}

	@Override
	public String deleteAllRfcs() throws IllegalArgumentException {

		int i = 0;
		DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
		Query q = new Query("RFC");
		PreparedQuery pq = ds.prepare(q);
		for (Entity rfc : pq.asIterable()) {
			ds.delete(rfc.getKey());
			i++;
		}

		q = new Query("WO");
		pq = ds.prepare(q);
		for (Entity wo : pq.asIterable()) {
			ds.delete(wo.getKey());
		}

		return "Deleted Rfcs:" + i;
	}

	// Work Orders

	@Override
	public String createWO(long id, Date planedStart, String CD, String CO,
			String woType, String desc, String serv, String cItem)
			throws IllegalArgumentException {
		try {
			if (this.woExists(id) == false) {

				DatastoreService ds = DatastoreServiceFactory
						.getDatastoreService();
				Key userKey = KeyFactory.createKey("WO", id);

				Entity wo = new Entity("WO", userKey);
				wo.setProperty("ID", id);
				wo.setProperty("PStart", planedStart);
				wo.setProperty("CD", CD);
				wo.setProperty("CO", CO);
				wo.setProperty("WoType", woType);
				wo.setProperty("Desc", desc);
				wo.setProperty("Serv", serv);
				wo.setProperty("CItem", cItem);
				wo.setProperty("State", "INITIAL");

				ds.put(wo);

				return "WO was created with ID: " + id;
			} else {
				return "WO already exists: " + id
						+ ".<br><br>Please contact your Administrator<br>";
			}
		}

		finally {
		}
	}

	@Override
	public String changeWO(long id, Date planedStart, Date planedEnd,
			Date actStart, Date actEnd, String planedEffort, String CD,
			String CO, String woType, String desc, String serv, String cItem,
			String state) throws IllegalArgumentException {
		try {
			if (this.woExists(id) == true) {
				DatastoreService ds = DatastoreServiceFactory
						.getDatastoreService();
				Query q = new Query("WO");
				q.addFilter("ID", Query.FilterOperator.EQUAL, id);
				PreparedQuery pq = ds.prepare(q);

				Entity wo = pq.asSingleEntity();

				wo.setProperty("ID", id);
				wo.setProperty("PStart", planedStart);
				wo.setProperty("PEnd", planedEnd);
				wo.setProperty("AStart", actStart);
				wo.setProperty("AEnd", actEnd);
				wo.setProperty("PEffort", planedEffort);
				wo.setProperty("CD", CD);
				wo.setProperty("CO", CO);
				wo.setProperty("WoType", woType);
				wo.setProperty("Desc", desc);
				wo.setProperty("Serv", serv);
				wo.setProperty("CItem", cItem);
				wo.setProperty("State", state);

				ds.put(wo);

				return "WO was changed successful";
			} else {
				return "WO dosn't exists: " + id
						+ ".<br><br>Please contact your Administrator<br>";
			}

		} finally {
		}
	}

	private boolean woExists(long id) {
		DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
		Query q = new Query("WO");
		q.addFilter("ID", Query.FilterOperator.EQUAL, id);
		PreparedQuery pq = ds.prepare(q);
		Entity wo = pq.asSingleEntity();
		if (wo == null)
			return false;
		return ((Long) wo.getProperty("ID") == id);
	}

	@Override
	public List<WO> fetchWO(int start, int length) {
		int i = 0;
		DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
		Query q = new Query("WO");
		q.addFilter("ID", Query.FilterOperator.GREATER_THAN, 0);
		q.addSort("ID", Query.SortDirection.ASCENDING);
		PreparedQuery pq = ds.prepare(q);
		List<WO> woList = new ArrayList<WO>();

		for (Entity wo : pq.asIterable()) {

			woList.add(new WO((Long) wo.getProperty("ID"), (Date) wo
					.getProperty("PStart"), (Date) wo.getProperty("PEnd"),
					(Date) wo.getProperty("AStart"), (Date) wo
							.getProperty("AEnd"), (String) wo
							.getProperty("PEffort"), (String) wo
							.getProperty("CD"), (String) wo.getProperty("CO"),
					(String) wo.getProperty("WoType"), (String) wo
							.getProperty("Desc"), (String) wo
							.getProperty("Serv"), (String) wo
							.getProperty("CItem"), (String) wo
							.getProperty("State")));

		}
		return woList;
	}

	// public void exportRfcs(ArrayList<Rfc> rfcs, String filePath) {
	// try {
	// FileOutputStream fos = new FileOutputStream(filePath);
	// XMLEncoder encoder = new XMLEncoder(fos);
	// encoder.writeObject(rfcs);
	// encoder.close();
	// } catch (FileNotFoundException e) {
	// e.printStackTrace();
	// }
	// }

	// public void exportRfcs(ArrayList<Rfc> rfcs, String filePath) {
	// try {
	// FileOutputStream fos = new FileOutputStream(filePath);
	// XMLEncoder encoder = new XMLEncoder(fos);
	// encoder.writeObject(rfcs);
	// encoder.close();
	// } catch (FileNotFoundException e) {
	// e.printStackTrace();
	// }
	// }

	// public void importRfcs(String filePath)
	// throws Exception {
	// FileInputStream os = new FileInputStream(filePath);
	// XMLDecoder decoder = new XMLDecoder(os);
	// @SuppressWarnings("unchecked")
	// ArrayList<Rfc> importedRfcs = (ArrayList<Rfc>)decoder.readObject();
	// decoder.close();
	//
	// for (Rfc rfc : importedRfcs) {
	// createRFC(rfc.getId(), rfc.getReason(), rfc.getDesc(),
	// rfc.getDetailDesc(),
	// rfc.getValidFrom(), rfc.getCI(), rfc.getCO(), rfc. getCA(),
	// rfc.getPrio(),
	// rfc.getCost(), rfc.getBenefit(), rfc.getRisk(), rfc.getServ(),
	// rfc.getcItem());
	// }
	// }
	//
	//
	// @Override
	// public String[] getCD() throws IllegalArgumentException {
	// // TODO Auto-generated method stub
	// return null;
	// }
	//
	// public void importRfcs(String filePath)
	// throws Exception {
	// FileInputStream os = new FileInputStream(filePath);
	// XMLDecoder decoder = new XMLDecoder(os);
	// @SuppressWarnings("unchecked")
	// ArrayList<Rfc> importedRfcs = (ArrayList<Rfc>)decoder.readObject();
	// decoder.close();
	//
	// for (Rfc rfc : importedRfcs) {
	// createRFC(rfc.getId(), rfc.getReason(), rfc.getDesc(),
	// rfc.getDetailDesc(),
	// rfc.getValidFrom(), rfc.getCI(), rfc.getCO(), rfc. getCA(),
	// rfc.getPrio(),
	// rfc.getCost(), rfc.getBenefit(), rfc.getRisk(), rfc.getServ(),
	// rfc.getcItem());
	// }
	// }

}
